import com.mysql.jdbc.jdbc2.optional.MysqlDataSource;

import javax.sql.DataSource;
import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.SQLException;

public class MysqlINSERT {
    public static void main(String[] args) throws SQLException {

        //1.创建并初始化数据源
        DataSource dataSource = new MysqlDataSource();
        ((MysqlDataSource)dataSource).setUrl("jdbc:mysql://127.0.0.1:3306/except?characterEncoding=utf8&useSSL=false");
        ((MysqlDataSource) dataSource).setUser("root");
        ((MysqlDataSource) dataSource).setPassword("040825lj");
        //2和数据库服务器链接
        Connection connection = dataSource.getConnection();
        //3 构造SQL语句
        String str ="insert into student value (1,'六')";
        PreparedStatement statement = connection.prepareStatement(str);
        //4 执行SQL
        int ret = statement.executeUpdate();
        System.out.println("ret = " + ret);
        //5 释放必要资源
        statement.close();
        connection.close();
    }
}
